/**
 * 属性：宽度 高度 纵轴坐标 横轴坐标 纵轴速度 横轴速度 dom对象
 */


class Rectangle {
    constructor(width, height, top, left, ySpeed, xSpeed, dom) {
        this.width = width;
        this.height = height;
        this.top = top;
        this.left = left;
        this.ySpeed = ySpeed;
        this.xSpeed = xSpeed;
        this.dom = dom;
        this.render();
    }
    render() {
        this.dom.style.width = this.width + "px";
        this.dom.style.height = this.height + "px";
        this.dom.style.top = this.top + "px";
        this.dom.style.left = this.left + "px";
    }
    /**
     * 
     * @param {时长} duration  移动的速度计算(px/秒)
     */
    move(duration) {
        const xDis = this.xSpeed * duration;
        const yDis = this.ySpeed * duration;
        this.left += xDis;
        this.top += yDis;
        if (this.onMove) {
            this.onMove();
        }

        this.render();
    }
}